package org.dormi.learn;

import org.dormi.learn.core.ItemSDO;
import org.dormi.learn.implA.InsuranceItem;
import org.dormi.learn.implA.ItemSDOFactory1;
import org.dormi.learn.implA.ItemSDOImplA;
import org.dormi.learn.implB.ItemSDOFactory2;
import org.dormi.learn.implB.ItemSDOImplB;
import org.dormi.learn.implB.PrimaryItem;
import org.eclipse.core.internal.runtime.AdapterManager;
import org.eclipse.core.runtime.IAdapterManager;

/**
 * add description here
 *
 * @author : dormi330
 * @version : 1.0
 */
public class Tester {
    public static void main(String[] args) {
        IAdapterManager manager = AdapterManager.getDefault();
        manager.registerAdapters(new ItemSDOFactory1(), ItemSDO.class);
        manager.registerAdapters(new ItemSDOFactory2(), ItemSDO.class);
        caseA(manager);
        caseB(manager);
    }

    private static ItemSDO caseA(IAdapterManager manager) {
        ItemSDO itemSDO = new ItemSDOImplA(1L, false, true);
        manager.loadAdapter(itemSDO, InsuranceItem.class.getName());

        InsuranceItem element = (InsuranceItem) manager.getAdapter(itemSDO, InsuranceItem.class);
        if (element != null && element.isInsurance()) {
            System.out.println("it is insurance");
        } else {
            System.out.println("it is not insurance");
        }

        itemSDO.doSomething();
        return itemSDO;
    }

    private static ItemSDO caseB(IAdapterManager manager) {
        ItemSDO itemSDO = new ItemSDOImplB(1L, true, true);

        PrimaryItem element = (PrimaryItem) manager.getAdapter(itemSDO, PrimaryItem.class);
        if (element != null && element.isPrimary()) {
            System.out.println("it is primary");
        } else {
            System.out.println("it is not primary");
        }

        itemSDO.doSomething();
        return itemSDO;
    }
}

